class Solution {
public:
    //快速幂
    double _myPow(double x, long long n)
    {
        if (n == 1)
            return x;

        bool flag = (n % 2 != 0);
        double ret = _myPow(x, n / 2);

        return flag ? ret * ret * x : ret * ret;
    }
    double myPow(double x, long long n) {
        if (n == 0)
            return 1;

        if (n < 0)
        {
            x = 1 / x;
            n *= -1;
        }
        
        return _myPow(x, n);
    }
};